﻿using JiveMessenger.ViewModels;
using System.Windows;
using System.Windows.Controls;

namespace JiveMessenger.Views
{
    /// <summary>
    /// Description for ResetPasswordWindow.
    /// </summary>
    public partial class ResetPasswordWindow : Window
    {
        /// <summary>
        /// Initializes a new instance of the ResetPasswordWindow class.
        /// </summary>
        public ResetPasswordWindow()
        {
            InitializeComponent();
            this.NewPasswordBox.Background.Opacity = 1;
            this.RepeatNewPasswordBox.Background.Opacity = 1;
        }

        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            ((ViewModelResetPasswordWindow)this.DataContext).Cleanup();
        }



        private void NewPasswordBox_GotFocus(object sender, RoutedEventArgs e)
        {
            ((PasswordBox)sender).Background.Opacity = 0;
        }
        private void NewPasswordBox_LostFocus(object sender, RoutedEventArgs e)
        {
            PasswordBox pb = (PasswordBox)sender;
            if (pb.Password.Length == 0)
                pb.Background.Opacity = 1;
        }
        private void RepeatNewPasswordBox_GotFocus(object sender, RoutedEventArgs e)
        {
            ((PasswordBox)sender).Background.Opacity = 0;
        }

        private void RepeatNewPasswordBox_LostFocus(object sender, RoutedEventArgs e)
        {
            PasswordBox pb = (PasswordBox)sender;
            if (pb.Password.Length == 0)
                pb.Background.Opacity = 1;
        }

        private void NewPasswordBox_PasswordChanged(object sender, RoutedEventArgs e)
        {
            PasswordBox pb = (PasswordBox)sender;
            ((ViewModelResetPasswordWindow)this.DataContext).PasswordChangedCommand.Execute(pb.SecurePassword);
        }

        private void RepeatNewPasswordBox_PasswordChanged(object sender, RoutedEventArgs e)
        {
            PasswordBox pb = (PasswordBox)sender;
            ((ViewModelResetPasswordWindow)this.DataContext).RepeatPasswordChangedCommand.Execute(pb.SecurePassword);
        }
    }
}